﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>数据模版</title>
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <link href="../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
    <!-- 导入配置文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script src="../Comm/Gener.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {

            $('Msg').val('正在加载请稍候....');

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("DBTemplate_Init");

            $('Msg').val('');

            if (data.indexOf('err@') == 0) {
                document.getElementById("Msg").innerHTML = data;
                return;
            }

            data = JSON.parse(data);
            var dbTemplate = data['DBTemplate'];
            var history = data['History'];

            var idx = 0;
            var html = "<table style='width:90%;'>";
            html += "<tr>";
            html += "<th colspan=3 >模版数据</th>";
            html += "</tr>";

            if (dbTemplate.length == 0) {
                html += "<tr>";
                html += "<td colspan=3>无</th>";
                html += "</tr>";
            }

            for (var i = 0; i < dbTemplate.length; i++) {
                var en = dbTemplate[i];
                html += "<tr>";
                html += "<td>" + i + "</td>";
                html += "<td><a href=\"javascript:Start('" + en.WorkID + "');\" >" + en.Title + "</td>";
                html += "<td><a href=\"javascript:DBTemplate_DeleteDBTemplate('" + en.WorkID + "');\" >删除</a></td>";
                html += "</tr>";
            }


            html += "<tr>";
            html += "<th colspan=3 >历史数据</th>";
            html += "</tr>";

            if (history.length == 0) {
                html += "<tr>";
                html += "<td colspan=3>无</th>";
                html += "</tr>";
            }

            for (var i = 0; i < history.length; i++) {
                var en = history[i];
                html += "<tr>";
                html += "<td>" + i + "</td>";
                html += "<td><a href=\"javascript:Start('" + en.WorkID + "');\" >" + en.Title + "</td>";
                html += "<td><a href=\"javascript:AddToTemplate('" + en.WorkID + "','" + en.Title + "');\" >设置模版</a></td>";
                html += "</tr>";
            }
            html += "<table>";
            document.getElementById("Msg").innerHTML = html;

            //$('Msg').val('');
            //document.getElementById("Msg").innerHTML = html;
        });

        function Start(workid) {

            if (window.confirm('您确定要以次模版发起流程吗？') == false)
                return;
            var url = '../MyFlow.htm?FK_Flow=' + GetQueryString('FK_Flow') + '&CopyFormWorkID=' + workid + '&CopyFormNode=' + GetQueryString('FK_Flow') + '01&IsDeleteDraft=1';

            window.parent.location.href = url;
            window.close();
        }

        function DBTemplate_DeleteDBTemplate(workid) {

            if (window.confirm('您确定要删除吗?') == false)
                return;

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            handler.AddPara("WorkID", workid);
            var data = handler.DoMethodReturnString("Accepter_Send");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
            alert(data);
            window.location.href = window.location.href;
        }

        function AddToTemplate(workid, title) {

            var name = window.prompt('请输入模版名称', title);
            if (name == null || name == '')
                return;

            name = encodeURI(name);

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            handler.AddPara("Title", name);
            var data = handler.DoMethodReturnString("DBTemplate_SaveAsDBTemplate");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
            alert(data);
            window.location.href = window.location.href;
        }
         
    </script>
    <style type="text/css">
        #tb_msg
        {
            height: 72px;
            width: 272px;
        }
    </style>
</head>
<body>
    <center>
        <div id="Msg">
            <img src='../Img/loading.gif' />正在加载请稍候...
        </div>
    </center>
</body>
</html>
